package com.yunxin.yundubbo.config;

import com.yunxin.yundubbo.enums.HandlerEnum;
import com.yunxin.yundubbo.interfaces.DubboHandler;
import com.yunxin.yundubbo.util.HandlerUtil;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class HandlerConfig {

    @Resource
    private List<DubboHandler> dubboHandlers;

    @PostConstruct
    private void init(){
        dubboHandlers.forEach(e->HandlerUtil.setCacheHandler(e.getType(),e));
    }


    public void registrationServices(HandlerEnum handlerEnum,DubboHandler dubboHandler){
        HandlerUtil.setCacheHandler(handlerEnum.getType(),dubboHandler);
    }

}
